Basic SDK Functions
The functions below are essential to start, stop and communicate with the VPN SDK.
You must have an active user account in order to create a minimum viable VPN product. Press the 'Add a New User' button at https://app.vpnwholesaler.com/users to create one.
At the bare minimum and considering that you already have login credentials for an active VPN account, you should implement the following functions and commands in order to create a minimum viable VPN product:
- Initialize SDK
- Set API domain
- Login
- Set VPN type
- Start VPN connection
- Stop VPN connection
- Finalize SDK
Initialize SDK
Intializes the SDK with a callback and sets necessary path to OpenVPN binary.
Login required: No Code: InitOVSCore Input:
- Java
- Kotlin
int InitOVSCore(OVSNotifyCB callback, Activity context)
int InitOVSCore(OVSNotifyCB callback, Activity context)
Input Parameters:
Callback - reference to callback function with following signature:
void (char* notify_data)
Response:
int - returns 0 if SDK was intialized sucessfully and other value in case of failure
Code sample:
It is recommended to implement event listener in your Activity class in the following way:
Android Code Sample - Event Listener
- Java
- Kotlin
public class SDKWrapper implements VPNSDK.CommandNotifyCB {
@Override
public void onNotify(int notification, int error, Object data) {
switch (notification) {
// Following is called when VPN status was changed
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECT_FAILED:
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_ABNOMARLY_DISCONNECTED:
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_DISCONNECTED: {
// Do something when VPN was disconnected
break;
}
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECTING: {
// Do something when VPN was started to connect
break;
}
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECTED: {
// Do something when VPN was connected
break;
}
// Following is called when we request VPN status explicitly
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_GET_STATUS: {
int state = (Integer)((Map)data).get("VPN_Status");
switch (state) {
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_DISCONNECTED:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_ABNORMALLY_DISCONNECTED:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONN_FAILED: {
// Do something when VPN was disconnected
break;
}
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_ASSIGNIP:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_GETCONFIG:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_AUTH:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONNECTING: {
// Do something when VPN was started to connect
break;
}
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONNECTED: {
// Do something when VPN was connected
break;
}
}
break;
}
}
}
}
public class SDKWrapper : CommandNotifyCB {
override fun onNotify(notification: Int, error: Int, data: Any?) {
when (notification) {
VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECT_FAILED,
VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_ABNOMARLY_DISCONNECTED,
VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_DISCONNECTED -> {
// Do something when VPN was disconnected
}
VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECTING -> {
// Do something when VPN was started to connect
}
VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECTED -> {
// Do something when VPN was connected
}
VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_GET_STATUS -> {
val state = (data as? Map<String, Int>)?.get("VPN_Status")
when (state) {
VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_DISCONNECTED,
VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_ABNORMALLY_DISCONNECTED,
VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONN_FAILED -> {
// Do something when VPN was disconnected
}
VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_ASSIGNIP,
VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_GETCONFIG,
VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_AUTH,
VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONNECTING -> {
// Do something when VPN was started to connect
}
VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONNECTED -> {
// Do something when VPN was connected
}
}
}
}
}
}
Then you can initialize the SDK using the following code:
- Java
- Kotlin
SDKWrapper wrapper = new SDKWrapper();
VPNSDK.InitOVSCore(wrapper, this);
val wrapper = SDKWrapper()
VPNSDK.InitOVSCore(wrapper, this)
Finalize SDK
Unloads SDK and finalizes all running threads. It is necessary to call this method before exit to avoid leaks.
Login required: No Code: FinalizeOVSCore() Input: None Response: None Code sample:
- Java
- Kotlin
VPNSDK.FinalizeOVSCore();
VPNSDK.FinalizeOVSCore();
Send command
Asynchronously sends command to SDK. Command result will be returned by calling the callback that was specified on initialization.
All operations in SDK are called asynchronously, and therefore a single callback is used to receive responses from all SDK functions. All responses are encoded as JSON and described in the relevant sections.
Login required: Depending on the command CmdProc Code: CmdProc(szCmdData) Input:
{
"cmd": int,
"data: { Command parameters }
}
Response: Generally, responses carry the following JSON structure:
{
"code": integer
"err": integer
"data": { object }
}
Where:
code - the invoked command's notification event. err - error code. data - response based on the notification code.